package com.example.smartplay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.smartplay.entity.Admin;
import com.example.smartplay.entity.Result;
import com.example.smartplay.entity.Student;
import com.example.smartplay.mapper.AdminMapper;
import com.example.smartplay.service.AdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartplay.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2024-07-11
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    // 登录
    @Override
    public Result login(String username, String password) {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        queryWrapper.eq("password", Md5Util.getMD5String(password));
        if (adminMapper.selectOne(queryWrapper) == null) {
            return Result.error("用户名或密码错误");
        }
        return Result.success(adminMapper.selectOne(queryWrapper));
    }
}
